<template>
  <view class="task">
    <nav-bar title="巡查巡检"></nav-bar>
    <view class="task-header">日常巡查</view>
    <view class="task-list">
      <van-cell v-for="task in taskList" :title="task.lineName" title-class="ellipsis" @click="!loading && getPatrolTaskCreated(task)" is-link />
    </view>
  </view>
</template>

<script setup>
import { ref } from 'vue';
import store from '@/store';
import { apiPatrolInspectListPage, apiPatrolTaskCreated } from '@/api/patrolInspect';
const userInfo = store.getters.GET_USER_INFO.sysUser;

let taskList = ref([]);
const loading = ref(false);

const getPatrolInspectListPage = () => {
  apiPatrolInspectListPage({
    pageSize: 1000,
    pageNum: 1,
  }).then(res => {
    taskList.value = res.data;
  })
};
const getPatrolTaskCreated = (task) => {
  loading.value = true;
  apiPatrolTaskCreated({
    lineId: task.lineId,
    checker: userInfo.userId,
    lineType: 0
  }).then(res => {
    loading.value = false;
    uni.navigateTo({ url: `/pages/patrolInspect/detail?id=${res}&lineId=${task.lineId}` })
  })
};
getPatrolInspectListPage();
</script>

<style lang="scss" scoped>
.task {
  &-header {
    padding-left: 30rpx;
    height: 100rpx;
    line-height: 100rpx;
    font-size: 40rpx;
  }
  &-list {
  }
  &-item {
    padding: 0 20rpx;
    margin-bottom: 20rpx;
    border-radius: 8rpx;
    height: 80rpx;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: linear-gradient(90deg, #1989fa , #87befc);
    color: $white;
  }
  &-title {
    flex: 1;
  }
}
</style>